Java读取resource文件/路径的几种方式 |
您所在的位置:网站首页 › java file 获取路径 › Java读取resource文件/路径的几种方式 |
示例路径结果:/E:/idea_work/sofn-qry-web/target/classes/CityJson.js 方式二: File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath()//标准的路径 ; String author =directory.getAbsolutePath()//绝对路径; ( 在jdk1.1后就有了此方法获取文件路径的方式存在了)示例路径结果:E:\idea_work\sofn-qry-web 方式三: java.net.URL uri = this.getClass().getResource("/"); ( 获取到Class文件存放的路径)示例路径结果:file:/E:/idea_work/sofn-qry-web/target/test-classes/ String property =System.getProperty("user.dir"); 方式四: String property =System.getProperty("user.dir"); ( 此方法可以得到该工程项目所有文件的相关路径及环境配置信息)示例输出结果:
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |